#include <algorithm>
#include <iostream>
#include <vector>

void fast_io() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

const int MAXN = 300005;

int n, m;
int a[MAXN];
std::vector<int> pos[MAXN];

int main() {
    fast_io();

    std::cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        std::cin >> a[i];
        pos[a[i]].push_back(i);
    }

    for (int i = 0; i < m; ++i) {
        int op;
        std::cin >> op;
        if (op == 1) {

            int l, r, c;
            std::cin >> l >> r >> c;

            auto it_l = std::lower_bound(pos[c].begin(), pos[c].end(), l);
            auto it_r = std::upper_bound(pos[c].begin(), pos[c].end(), r);

            std::cout << (it_r - it_l) << "\n";

        } else {

            int x;
            std::cin >> x;

            int c1 = a[x];
            int c2 = a[x + 1];

            if (c1 == c2) {
                continue;
            }

            auto it1 = std::lower_bound(pos[c1].begin(), pos[c1].end(), x);

            *it1 = x + 1;

            auto it2 = std::lower_bound(pos[c2].begin(), pos[c2].end(), x + 1);

            *it2 = x;

            std::swap(a[x], a[x + 1]);
        }
    }

    return 0;
}
